package com.qdevelop.control.action;

import java.util.Map;

import com.qdevelop.control.bean.QueryBean;
import com.qdevelop.control.bean.QueryConfigBean;
import com.qdevelop.control.bean.ResultBean;
import com.qdevelop.model.service.database.DBFactory;
import com.qdevelop.model.utils.QdevelopUtils;
import com.qdevelop.security.SecurityCache;

@SuppressWarnings("serial")
public class MenuAction extends QDevelopBaseAction{
	
	ResultBean rb;
	public String list() throws Exception {
		QueryBean qb = QdevelopUtils.getInstance().getQueryBean(this.getParamMap(),LoginAction.getLoginUserRoles());
		rb = DBFactory.getInstance().getQueryResult(qb);
		return SUCCESS;
	}
	
	@SuppressWarnings("unchecked")
	public String update() throws Exception {
		Map tmp = this.getParamMap();
		if(!this.isRepeatSubmit(tmp) && tmp!=null && tmp.size()>0){
			QueryBean qb = QdevelopUtils.getInstance().getQueryBean(new QueryConfigBean(tmp),LoginAction.getLoginUserRoles());
			DBFactory.getInstance().updateBySQL(qb);
			SecurityCache.getInstance().resetMenuUrlCache();
		}
		return SUCCESS; 
	}

	@SuppressWarnings("unchecked")
	public String updateBat() throws Exception {
		Map tmp = this.getParamMap();
		if(!this.isRepeatSubmit(tmp)){
			QueryBean[] qb = QdevelopUtils.getInstance().getMultiQueryBean(new QueryConfigBean(tmp));
			DBFactory.getInstance().updateBySQL(qb);
		}
		return SUCCESS; 
	}

	public ResultBean getRb() {
		return rb;
	}

	public void setRb(ResultBean rb) {
		this.rb = rb;
	}

}
